<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>渠道编辑</title>
    <link rel="stylesheet" href="/res/frame/layui/css/layui.css">
    <link rel="stylesheet" href="/res/frame/static/css/style.css">
    <link rel="icon" href="/res/frame/static/image/code.png">
</head>
<body class="body">




<div class="layui-form-item">
    <label class="layui-form-label">渠道名称:</label>
    <div class="layui-input-inline">
        <input type="text" id='chName'  placeholder="请输入名称" lay-verify="required"
               class="layui-input" autocomplete="off">
    </div>
</div>


<div class="layui-form-item">
    <label class="layui-form-label" >是否隐藏：</label>
    <div class="layui-input-inline" >
        <select  class="layui-input" name="modules" id="chOnoff" lay-verify="required">
            <option value="T">是</option>
            <option value="F">否</option>
        </select>
    </div>
</div>
<div class="layui-form-item">
    <label class="layui-form-label">起始条数:</label>

    <div class="layui-input-inline">
        <input type="text" id='chBegSize' lay-verify="required" placeholder="起始条数"
               class="layui-input" autocomplete="off">
    </div>
</div>


<div class="layui-form-item">
    <label class="layui-form-label">隐藏比例:</label>
    <div class="layui-input-inline">
        <input type="text" id='chRatio' lay-verify="required" placeholder="隐藏比例"
               class="layui-input" autocomplete="off">
    </div>
</div>
<div class="layui-form-item">
    <label class="layui-form-label">注册链接:</label>

    <div class="layui-input-inline">
        <input type="text" id='chUrl' lay-verify="required" placeholder="注册链接"
               class="layui-input" autocomplete="off">
    </div>
</div>



<div class="layui-layer-btn layui-layer-btn-c">
    <button type="button" class="layui-btn layui-btn-normal layui-btn-radius" id="sub">提交</button>
</div>

<script src="/res/frame/layui/layui.js" charset="utf-8"></script>
<script type="text/javascript" src="/res/js/index.js"></script>
<script type="text/javascript">

    layui.use(['form', 'layedit', 'laydate', 'element', 'cookie'], function () {
        // 操作对象
        var form = layui.form
            , table = layui.table
            , layer = layui.layer
            , vipTable = layui.vip_table
            , $ = layui.jquery,
            cookie = layui.cookie,
            laydate = layui.laydate;

        function GetQueryString(name) {
            var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
            var r = window.location.search.substr(1).match(reg);
            if (r != null) return unescape(r[2]);
            return null;
        }

        init();
        $('#sub').on('click', function () {
            var params={};
            params.chName = $("#chName").val();
            params.chOnoff = $("#chOnoff").val();
            params.chBegSize = $("#chBegSize").val();
            params.chRatio = $("#chRatio").val();
            params.chUrl = $("#chUrl").val();
            params.pkGuid=GetQueryString("pkGuid");
            $.ajax({
                url: "/channel/updateChannel",
                type: "post",
                contentType: "application/json",
                data: JSON.stringify(params),
                success: function (result) {
                    console.log(result)
                    if (result.code === 200) {
                        layer.alert(result.msg);
                        setTimeout(function () {
                            parent.location.reload();
                        }, 3000);
                    } else if (result.code === 201) {
                        layer.alert(result.msg);
                    } else {
                        layer.alert(result.msg);
                    }
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    console.log(XMLHttpRequest.responseText);

                }
            });
        });

        function init() {
            if (GetQueryString("pkGuid") != "0") {
                $.ajax({
                    url: "/channel/selectChannelById?pkGuid=" + GetQueryString("pkGuid"),
                    type: "get",
                    success: function (result) {
                        console.log(result)
                        if (result.code === 200) {
                           $("#chName").val(result.data.chName);
                           $("#chOnoff").val(result.data.chOnoff);
                           $("#chBegSize").val(result.data.chBegSize);
                           $("#chRatio").val(result.data.chRatio);
                           $("#chUrl").val(result.data.chUrl);
                        }
                    },
                    error: function (XMLHttpRequest, textStatus, errorThrown) {
                        console.log(XMLHttpRequest.responseText);
                    }
                });


            }
        }

    });


</script>
</body>
</html>